﻿using System;
using System.IO;
using System.Web;
using System.Web.UI;

namespace ControlExplorer.samples.ExcelCompatibility
{
  public partial class Overview : SpreadDemoPage
  {
    protected void Page_Load(object sender, System.EventArgs e)
    {
      if (!Page.IsPostBack)
      {
          string fileName = MapPath("考核表工作表.xls");
        OpenExcelFile(fileName);

        FpSpread1.Sheets[0].AllowPage = false;
        FpSpread1.ClientAutoCalculation = true;
        this.FpSpread1.UseClipboard = false;
      }
    }

    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
      //
      // CODEGEN: This call is required by the ASP.NET Web Form Designer.
      //
      InitializeComponent();
      base.OnInit(e);
    }

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {

    }
    #endregion

    public void OpenExcelFile(string filename)
    {
      //Open
      try
      {
        FpSpread1.OpenExcel(filename);
      }
      catch (Exception ex)
      {
      }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
      FpSpread1.SaveExcelToResponse("spreadweb_export.xls");
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
      FpSpread1.SaveExcelToResponse("spreadweb_export.xlsx", FarPoint.Excel.ExcelSaveFlags.UseOOXMLFormat);
    }

    protected void Button3_Click(object sender, EventArgs e)
    {
      HttpPostedFile file = Request.Files["myFile"];
      if (file != null && file.ContentLength != 0)
      {
        string fname = Server.MapPath(Path.Combine("~/samples/ExcelCompatibility", Path.GetFileName(file.FileName)));
        // post file to application folder first (to avoid "Error Opening File" exception since the file is being used also by browser)
        file.SaveAs(fname);
        // open the posted Excel file
        OpenExcelFile(fname);
      }
    }
  }
}